﻿@model IdNameDTO[]
@{
    ViewBag.Title = "List";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<section class="layui-larry-box">
    <div class="larry-personal">
        <div class="layui-tab">
            <blockquote class="layui-elem-quote idName_search">
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-normal idNameAdd_btn">添加字典</a>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-danger batchDel">批量删除</a>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-mid layui-word-aux">本页面刷新后除新添加的文章外所有操作无效，关闭页面所有数据重置</div>
                </div>
                <div class="layui-inline">
                    <span class="layui-form-mid">共有<span style="font-weight: bold">@ViewBag.totalCount </span>条数据</span>
                </div>
            </blockquote>

            <!-- 操作日志 -->
            <div class="layui-form idName_list">
                <table class="layui-table">
                    <colgroup>
                        <col width="10%">
                        <col>
                        <col>
                        <col>
                        <col>
                    </colgroup>
                    <thead>
                        <tr>
                            <th>
                                <input name="" lay-skin="primary" lay-filter="allChoose" id="allChoose" type="checkbox">
                                <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                                    <i class="layui-icon"></i>
                                </div>
                            </th>
                            <th>类型名</th>
                            <th>名称</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody class="idName_content">
                        @foreach (var idName in Model)
                        {
                            <tr>
                            <td>
                                <input name="checked" lay-skin="primary" lay-filter="choose" type="checkbox">
                                <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div>
                            </td>
                            <th>@idName.TypeName</th>
                            <th>@idName.Name</th>
                            <th>@idName.CreateDateTime</th>

                            <td>
                                <a class="layui-btn layui-btn-mini idName_edit" data-id="@idName.Id"><i class="iconfont icon-edit"></i> 编辑</a>
                                <a class="layui-btn layui-btn-danger layui-btn-mini idName_del" data-id="@idName.Id">
                                    <i class="layui-icon"></i> 删除
                                </a>
                            </td>
                        </tr>
                        }
                        

                    </tbody>
                </table>
                <div class="larry-table-page clearfix">
                    <div id="page" class="page"></div>
                </div>
            </div>

        </div>
    </div>

</section>

@section FooterScript{
<script>
    var appConfig = {
        name: "idName",    //需要和页面名称对应
        title: "评论",    //显示的名称
        addUrl: "/IdName/AddNew",   //添加弹框的路径
        editUrl: "/IdName/Edit?idNameId=",      //修改弹框的路径
        $: "",
        layer: "",
        area:['100%','800px'],

        // 批量删除Ajax
        batchDel: function (data) {     //Array data 得到的是 需要删除的id
            $ = appConfig.$
            $.ajax({
                url: "/IdName/BatchDel",
                method: "post",
                dataType: "json",
                data: { "idNameIds": data },    //$(data)要删除的数组
                traditional: true,//这里设置为true
                success: function (res) {
                    if (res.status == "ok") {
                        appConfig.layer.msg("删除成功", {
                            icon: 1, time: 1000, end: function () {
                                location.reload();
                            }
                        });



                    } else {
                        appConfig.layer.msg("删除失败", {
                            icon: 5, time: 1000, end: function () {
                                location.reload();
                            }
                        });
                    }
                },
                error: function () {
                    appConfig.layer.msg("删除失败", {
                        icon: 5, time: 2000, end: function () {
                            location.reload();
                        }
                    });

                    location.reload();
                }
            });

        },
        // 软删除
        del: function (data) {

            console.log(data);
            $ = appConfig.$
            //todo:在此处添加删除记录的ajax
            $.ajax({
                url: "/IdName/Delete/",
                method: "post",
                dataType: "json",
                data: { "idNameId": data },
                success: function (res) {
                    if (res.status == "ok") {
                        appConfig.layer.msg("删除成功", { icon: 1 });

                    } else {
                        appConfig.layer.msg("删除失败", { icon: 5 });
                    }
                },
                error: function () {
                    appConfig.layer.msg("删除失败", { icon: 5 });
                }
            });
        },



    };

</script>
    
    }

